# !/usr/bin/env python
# coding: utf-8
"""
#!!================================================================
#版权 (C) 2023, Huawei Technologies Co.
#==================================================================
#文 件 名：                 Example.py
#文件说明：                 Example TestScript
#作    者：                 author
#生成日期：                 2023-07-13
#!!================================================================
"""
from random import random, randint

from devicetest.core.test_case import TestCase, Step
from hypium import *
from hypium.model import UiParam

direction_dict = {
    1: UiParam.UP,
    2: UiParam.DOWN,
    3: UiParam.LEFT,
    4: UiParam.RIGHT,
}

class Example(TestCase):
    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)
        self.driver = UiDriver(self.device1)

    def setup(self):
        Step('1.回到桌面')
        self.driver.swipe_to_home()

    def process(self):
        Step('2.随机点击浏览器应用')
        self.driver.start_app('com.huawei.hmos.browser')
        count = 0
        while count <= 30:
            x = random()
            y = random()
            scroll = randint(1, 4)
            self.driver.touch((x, y))
            # 向对应方向距离滑动 40
            self.driver.swipe(direction_dict.get(scroll), distance=40)
            count += 1


    def teardown(self):
        Step('4.执行清理操作')
